package com.offcn.service.impl;

import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.offcn.dao.TSetmealMapper;
import com.offcn.pojo.TSetmeal;
import com.offcn.service.TSetmealService;
import com.offcn.util.PageResult;
import com.offcn.util.QueryPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
@Service
public class TSetmealServiceImpl implements TSetmealService {
  /*  @Autowired
    private TSetmealMapper tSetmealMapper;

    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        Page<TSetmeal> page = new Page<>(pageBean.getCurrentPage(), pageBean.getPageSize());
        QueryWrapper<TSetmeal> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(pageBean.getQueryString())){
            wrapper.like("code",pageBean.getQueryString());
            wrapper.or();
            wrapper.like("name",pageBean.getQueryString());
            wrapper.or();
            wrapper.like("helpCode",pageBean.getQueryString());
        }
        Page<TSetmeal> tSetmealPage = tSetmealMapper.selectPage(page, wrapper);
        PageResult pageResult = new PageResult(tSetmealPage.getTotal(), tSetmealPage.getRecords());
        return pageResult;
    }*/
    @Autowired
    private TSetmealMapper tSetmealMapper;

    //分页查询
    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        Page<TSetmeal>page = new Page<>(pageBean.getCurrentPage(),pageBean.getPageSize());
        QueryWrapper<TSetmeal>wrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(pageBean.getQueryString())){
            wrapper.like("code",pageBean.getQueryString());
            wrapper.or();
            wrapper.like("name",pageBean.getQueryString());
            wrapper.or();
            wrapper.like("helpCode",pageBean.getQueryString());
        }
        Page<TSetmeal> setmealPage = tSetmealMapper.selectPage(page, wrapper);
        System.out.println(setmealPage.toString());
        return new PageResult(setmealPage.getTotal(),setmealPage.getRecords());
    }
}
